//
//  PhotoAction.m
//  XPhoto
//
//  Created by baboy on 2019/7/5.
//  Copyright © 2019 baboy. All rights reserved.
//

#import "PostAction.h"
#import <BKKit/BKApi.h>
#import "HttpResponse.h"


@implementation PostAction

+ (id)addLike:(PostAction*)action callback:(nullable void (^)(id _Nonnull task, id _Nullable json,  NSError * _Nullable error))callback{
    id task = [BKApi request:API_POST_ACTION_ADD_LIKE
                parameters:action
                  callback:^(id  _Nonnull task, id  _Nullable json, NSError * _Nullable error) {
                      HttpResponse *response = [HttpResponse responseWithDictionary:json];
                      if (!error && ![response isSuccess]) {
                          error = [NSError errorWithDomain:HttpRequestDomain code:response.status userInfo:@{NSLocalizedDescriptionKey:response.msg}];
                      }
                      if (callback) {
                          callback(task,response.data, error);
                      }
                  }];
    return task;
}
+ (id)addShare:(PostAction*)action callback:(nullable void (^)(id _Nonnull task, id _Nullable json,  NSError * _Nullable error))callback{
    id task = [BKApi request:API_POST_ACTION_ADD_SHARE
                parameters:action
                  callback:^(id  _Nonnull task, id  _Nullable json, NSError * _Nullable error) {
                      HttpResponse *response = [HttpResponse responseWithDictionary:json];
                      if (!error && ![response isSuccess]) {
                          error = [NSError errorWithDomain:HttpRequestDomain code:response.status userInfo:@{NSLocalizedDescriptionKey:response.msg}];
                      }
                      if (callback) {
                          callback(task,response.data, error);
                      }
                  }];
    return task;
    
}
+ (id)addFav:(PostAction*)action callback:(nullable void (^)(id _Nonnull task, id _Nullable json,  NSError * _Nullable error))callback{
    id task = [BKApi request:API_POST_ACTION_ADD_FAV
                parameters:action
                  callback:^(id  _Nonnull task, id  _Nullable json, NSError * _Nullable error) {
                      HttpResponse *response = [HttpResponse responseWithDictionary:json];
                      if (!error && ![response isSuccess]) {
                          error = [NSError errorWithDomain:HttpRequestDomain code:response.status userInfo:@{NSLocalizedDescriptionKey:response.msg}];
                      }
                      if (callback) {
                          callback(task,response.data, error);
                      }
                  }];
    return task;
    
}
@end
